package org.ysh.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Properties;

@Slf4j
@Component
public class CaptchaConfig {

    @Bean
    public Producer producer(){
        DefaultKaptcha producer = new DefaultKaptcha();
        Properties prop = new Properties();
        try {
            prop.load(this.getClass().getResourceAsStream("/captcha.properties"));
        } catch (IOException e) {
            log.error("加载Captcha配置文件失败，请检查文件是否存在",e);
        }
        Config config = new Config(prop);
        producer.setConfig(config);
        return producer;
	}

}
